<template>
  <!--推荐的上架商品-->
  <div class="recom">
    <div class="categoryName">我的攻略</div>
    <!-- 攻略列表 -->
    <div class="max-w-7xl mx-auto px-4 pb-24">
      <div v-if="pageInfo.list" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
        <div v-for="guide in pageInfo.list"
             :key="guide.id"
             class="bg-white rounded-lg shadow-sm overflow-hidden"
             @click="toGuideView(guide.id)"
        >
          <div class="relative h-48 overflow-hidden">
            <img :src="SERVER_ADDR + '/scenicSpot/pic/' + guide.pic" class="w-full h-full object-cover object-top" :alt="guide.title" />
          </div>
          <div class="p-4">
            <h3 class="text-lg font-bold mb-2">{{ guide.title }}</h3>
            <p class="text-gray-600 text-sm mb-4 line-clamp-2">{{ guide.description }}</p>
            <div class="flex items-center justify-between text-sm text-gray-500">
              <span>{{ guide.departureDate }}</span>
              <div class="flex items-center gap-4">
                <span class="flex items-center gap-1">
                  <el-icon><ChatDotRound /></el-icon>
                  {{ guide.comments.length }}
                </span>
                <span class="flex items-center gap-1">
                  <el-icon><Star /></el-icon>
                  20
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 空状态 -->
      <div v-else class="text-center py-20">
        <el-empty description="暂无攻略内容">
          <el-button type="primary" class="!rounded-button whitespace-nowrap">去创建</el-button>
        </el-empty>
      </div>
    </div>
  </div>
  <div class="collectNav">
    <el-row justify="center">
      <el-pagination background layout="prev, pager, next"
                     :page-count="pageInfo.pages"
                     @update:current-page="getUserStrategy"
                     style="margin-top: 10px; text-align: center"
                     v-model:current-page="pageInfo.pageNum" />
    </el-row>

  </div>
</template>

<script setup>
import {ref} from "vue";
import {useRouter} from "vue-router";
import strategyApi from '@/api/strategyApi';
//服务器的地址
const SERVER_ADDR = ref(import.meta.env.VITE_SERVER_ADDR)
const pageInfo = ref({});
const router = useRouter();
const getUserStrategy = (pageNum) => {
  strategyApi.selectByUser(pageNum,5 )
      .then(resp => {
        if (resp.code == 10000) {
          pageInfo.value = resp.data;
        }
      })
}
// 跳转到攻略详情页
const toGuideView = (id)=>{
  router.push({
    path: '/user/strategy',
    query: {
      id
    }
  });
}
getUserStrategy(1);
</script>

<style scoped>
.ad {
  margin: 20px 0;
}
.ad ul li {
  float: left;
  width: 285px;
  margin-right: 20px;
}
.ad ul li:last-child{
  margin-right: 0px;
}
.recom .goodsList ul li {
  width: 224px;
  float: left;
  margin-right: 20px;
  margin-bottom: 15px;
  text-align: center;
  background-color: #fff;
  cursor: pointer;
}
.recom .goodsList ul li:hover{
  box-shadow: 0px 0px 20px #000;
}
.recom .goodsList ul li:nth-child(5n) {
  margin-right: 0px;
}

.recom {
  margin-bottom: 20px;
}

.recom .categoryName {
  font-size: 20px;
  margin-bottom: 5px;
  font-weight: bold;
}
.name, .dscp, .price{
  line-height: 25px;
}
.recom .name {
  font-size: 16px;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recom .dscp {
  color: #aaa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recom .price {
  font-size: 12px;
  color:  var(--theme-color);
}
.collectNav {
  padding: 10px;
  background-color: #ffffff;
}

</style>